home *** CD-ROM | disk | FTP | other *** search
- /* %filename% */
- /* Created %date% %time% by AppMaker */
-
- #include <Types.h>
- #include <Quickdraw.h>
- #include <Controls.h>
- #include <Dialogs.h>
- #include <Events.h>
- #include <Lists.h>
- #include <Menus.h>
- #include <TextEdit.h>
- #include <Desk.h>
- #include <Packages.h>
- #include <ToolUtils.h>
- %if lang = AUX%
- #include "resdefs.h"
- #include "dispatcher.h"
- #include "miscellany.h"
- %else%
- #include "ResourceDefs.h"
- #include "Dispatcher.h"
- #include "Miscellany.h"
- %endif%
- #include "Globals.h"
- %for each menuItem gen includeDialog%
- #include "%appName%Data.h"
- #include "%menuname%M.h"
-
- #define dialogTop 75
- #define dialogLeft 85
-
- %if lang = MPW%
- #pragma segment %menuname%
-
- %end if%
-
- short numOpenTypes;
- SFTypeList openTypeList;
-
- static void CloseAppWindow (void);
- %for each menuitem gen doItemProto%
-
- /*----------*/
- void Init%MenuName%M (void)
- {
- %if lang = AUX%
- numOpenTypes = 2;
- openTypeList [0] = kFileType;
- openTypeList [1] = 'A/UX';
- %else%
- numOpenTypes = 1;
- openTypeList [0] = kFileType;
- %endif%
- } /*Init%MenuName%M*/
-
- /*----------*/
- Boolean OkToOpen (OSType fType)
- {
- short i;
- enum {searching, found, notFound}
- status;
-
- i = 0;
- status = searching;
- while (status == searching) {
- if (i >= numOpenTypes) {
- status = notFound;
- } else {
- if (fType == openTypeList [i]) {
- status = found;
- } else {
- i++;
- }
- }
- } /*while*/
- return (status == found);
- } /*OkToOpen*/
-
- /*----------*/
- static void DoNew (void)
- {
- OpenWindows ("\p", 0, 0);
- InitAppData ();
-
- } /*DoNew*/
-
- /*----------*/
- void OpenDoc (Str255 fileName,
- short vRefNum)
- {
- /* This *should* be defined in an Apple interface file: */
- #define StationeryFlag 0x0800
-
- Boolean isStationery;
- FInfo finderInfo;
- short fRefNum;
-
- isStationery = false;
- if (GetFInfo (fileName, vRefNum, &finderInfo) == noErr) {
- if ((finderInfo.fdFlags & StationeryFlag) != 0) {
- isStationery = true;
- }
- }
- if (OpenAppFile (vRefNum, fileName, &fRefNum)) {
- if (isStationery) {
- OpenWindows ("\p", 0, 0);
- ReadAppFile (fRefNum);
- CloseAppFile (fRefNum);
- } else {
- OpenWindows (fileName, vRefNum, fRefNum);
- ReadAppFile (fRefNum);
- }
- }
- } /*OpenDoc*/
-
- /*----------*/
- static void DoOpen (void)
- {
- Point dialogOrigin;
- SFReply sfInfo;
-
- SetPt (&dialogOrigin, dialogLeft, dialogTop);
- SFGetFile (dialogOrigin, "\p", nil, numOpenTypes, openTypeList, nil, &sfInfo);
- if (sfInfo.good) {
- OpenDoc (sfInfo.fName, sfInfo.vRefNum);
- }
- } /*DoOpen*/
-
- /*----------*/
- void OpenApp (void)
- {
- DoNew ();
- } /*OpenApp*/
-
- /*----------*/
- static void DoSaveAs (void)
- {
- SFReply sfInfo;
- short fRefNum;
- StringHandle prompt;
- Str255 suggestion;
-
- prompt = GetString (SaveAsPromptID);
- suggestion [0] = 0;
-
- if (CreateFile (&sfInfo, *prompt, suggestion, kSignature, kFileType)) {
- CloseAppFile (cur->fileNum);
- if (OpenAppFile (sfInfo.vRefNum, sfInfo.fName, &fRefNum)) {
- SetWTitle (curWindow, sfInfo.fName);
- cur->fileNum = fRefNum;
- cur->volNum = sfInfo.vRefNum;
- WriteAppFile (cur->fileNum);
- cur->dirty = false;
- } else { /*should never happen*/
- SetWTitle (curWindow, "\p???");
- cur->fileNum = 0;
- cur->volNum = 0;
- }
- }
- } /*DoSaveAs*/
-
- /*----------*/
- static void DoSave (void)
- {
- if (cur->fileNum == 0) {
- DoSaveAs ();
- } else {
- WriteAppFile (cur->fileNum);
- cur->dirty = false;
- }
- } /*DoSave*/
-
- /*----------*/
- static void CloseAppWindow (void)
- {
- enum {saveItem = 1, cancelItem, discardItem};
-
- Str255 curTitle;
- short itemNum;
- Boolean okay;
-
- okay = true;
- SetInfo (FrontWindow ());
- if (cur->dirty) {
- GetWTitle (curWindow, curTitle);
- ParamText (curTitle, "\p", "\p", "\p");
- InitCursor ();
- itemNum = Alert (SaveID, nil);
- switch (itemNum) {
- case saveItem:
- DoSave ();
- okay = !errorFlag;
- break;
- case discardItem:
- /*Do nothing*/;
- break;
- case cancelItem:
- errorFlag = true;
- okay = false;
- break;
- } /*switch*/
- }
- if (okay) {
- DisposeAppData ();
- if (cur->windowKind == 1) { /* 1st or only window in set */
- CloseAppFile (cur->fileNum);
- }
- CloseCurWindow ();
- }
- } /*CloseAppWindow*/
-
- /*----------*/
- void DoClose (void)
- {
- WindowPeek frontPeek;
-
- errorFlag = false;
-
- frontPeek = (WindowPeek) FrontWindow ();
- if (frontPeek->windowKind < 0) {
- CloseDeskAcc (frontPeek->windowKind);
- } else if (frontPeek->windowKind == dialogKind) {
- CloseModelessDialog (FrontWindow ());
- } else {
- CloseAppWindow ();
- }
- } /*DoClose*/
-
- /*----------*/
- void DoQuit (void)
- {
- Boolean quitting;
-
- quitting = true;
- while (quitting && (FrontWindow () != nil)) {
- SystemTask ();
- DoClose ();
- if (errorFlag) {
- quitting = false;
- }
- } /*while*/
-
- if (quitting) {
- quittingTime = true;
- }
- } /*DoQuit*/
-
- %for each menuitem gen doItem%
- /*----------*/
- void Do%MenuName% (short itemNr)
- {
- errorFlag = false;
-
- switch (itemNr) {
- %for each menuitem gen handleitem%
-
- } /*switch*/
- } /*Do%MenuName%*/
-
- /* %menuname% */
-